package com.et.generator.impl.adapter;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Mysql</p>
 * @author defier Lai
 * <p>Date: 2009-12-6 下午11:52:58</p>
 * @version 1.0
 */
public class Mysql extends Executor {

	@Override
	protected List<String> getTables(Connection conn) throws SQLException {
		String[] types = { "TABLE" };
		ResultSet resultSet = conn.getMetaData().getTables(null, null, "%", types);
		List<String> tables = new ArrayList<String>();
		while (resultSet.next()) {
		 	String tableName = resultSet.getString("TABLE_NAME");
		 	tables.add(tableName);
		}
		resultSet.close();
		return tables;
	}

	@Override
	protected String getColumnType(String type) {
		if (type.trim().equalsIgnoreCase("Integer")){
			type = "Integer";
		} else if (type.trim().equalsIgnoreCase("Varchar")) {
			type = "String";
		} else if (type.trim().equalsIgnoreCase("BIGINT")) {
			type = "Long";
		} else if (type.trim().equalsIgnoreCase("DOUBLE")) {
			type = "Double";
		} else if (type.trim().equalsIgnoreCase("FLOAT")) {
			type = "Float";
		} else if (type.trim().equalsIgnoreCase("Timestamp")) {
			type = "Timestamp";
		} else if (type.trim().equalsIgnoreCase("Date")) {
			type = "Date";
		} else if (type.trim().equalsIgnoreCase("Datetime")) {
			type = "Timestamp";
		} else if (type.trim().equalsIgnoreCase("TIME")) {
			type = "Time";
		} else if (type.trim().equalsIgnoreCase("YEAR")) {
			type = "Date";
		} else {
			type = "String";
		}
		return type;
	}

}
